define(['app', 'pagination', 'datetime', 'autocomplete', 'editor', 'filesaver', 'fileupload'], function(app) {
    'use strict';
    app.controller('ProductLine', function($scope, dataFactoryCRM, $q, Upload, $http, $rootScope) {
        $scope.productLinePage = { pageAll: 1, pageNow: 1, pageSize: $scope.psize, k: 3 };    //分页参数
        $scope.search_param = { name: ''};   //页面搜索参数
        $scope.productline_list;

        /**获取列表页 */
        $scope.getProductLineList = function() {
            var listParam = $scope.search_param;
            listParam['psize'] = $scope.productLinePage.pageSize;
            listParam['p'] = $scope.productLinePage.pageNow;
            var search_url = 'ProductLine/index?' + $.param(listParam);
            dataFactoryCRM.getDataByAPI(search_url).then(function(returnDate) {
                $scope.rcode = returnDate.rcode;
                $scope.productLinePage.pageSize = returnDate.psize;
                $scope.productLinePage.pageAll = returnDate.pall;
                $scope.productLinePage.pageNow = returnDate.p;
                if(returnDate.data){
                    var qyDate = {};
                    for (var i = returnDate.data.length - 1; i >= 0; i--) {
                        qyDate[i] = '';
                        for (var j = returnDate.data[i].qyDate.length - 1; j >= 0; j--) {
                            qyDate[i] += returnDate.data[i].qyDate[j].qy_name+'、';  //企业号用'、'连接
                        };
                        if(qyDate[i])
                            qyDate[i] = qyDate[i].substring(0,qyDate[i].length-1);//去掉最后一位的'、'
                        returnDate.data[i]['qyDate'] = qyDate[i];
                    };
                }
                $scope.productline_list = returnDate.data;
            });
        };
        /**搜索事件**/
        $scope.search = function() {
            $scope.getProductLineList();
        }

        /*产品线跳转到产品页面*/
        $scope.viewProduct = function(product_line_code){
            $rootScope.go('/product/'+product_line_code);
        }

        //初始化页面显示数据（如果是新弹出独立窗口则从父窗口获取）
        window.loadClientCacheToScope($scope, function(){
           $scope.getProductLineList();
        });
    });
})